﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Ample.BLL.User;
using Ample.Model;

public partial class Admin_Boards_CreateBoard : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if(!Page.IsPostBack)
        {
            BoardBO boardBO = new BoardBO();
            ddlBoardType.DataSource = boardBO.GetBoardTypes();
            ddlBoardType.DataBind();

            if (!string.IsNullOrEmpty(Request.QueryString["Board"]))
            {
                string code = Request.QueryString["Board"];
                Board board = boardBO.GetBoardByCode(code);

                txtBoardCode.Text = Server.HtmlEncode(board.BoardCode);
                ddlBoardType.SelectedValue = board.BoardTypeName;
                chkOpen.Checked = board.IsOpen;
            }
        }
    }
    protected void lBtnSave_Click(object sender, EventArgs e)
    {
        Board board = new Board();

        board.StartDate = DateTime.Now;

        if (!string.IsNullOrEmpty(Request.QueryString["Board"]))
        {
            BoardBO boardBO = new BoardBO();
            string code = Request.QueryString["Board"];
            board = boardBO.GetBoardByCode(code);
        }

        board.BoardTypeName = ddlBoardType.SelectedValue;
        board.IsOpen = chkOpen.Checked;
        board.BoardCode = txtBoardCode.Text;
        
        BoardBO boardBOSave = new BoardBO();
        boardBOSave.SaveBoard(board);

        Response.Redirect("~/Admin/Boards/ManageBoards.aspx");
    }
}
